<?php
class YongjinAction extends AdminAction {

	#列表
	public function index() {

		$userid  = I('get.userid');

		$obj = M('Yongjin');

		if($userid!=''){
			$map['toUserID'] = $userid;
		}

		$count = $obj->where($map)->count();
		import("@.ORG.Page");
		$page = new Page($count, 20);
		$show = $page->show();
		$list = $obj->where($map)->order('id desc')->limit($page->firstRow . ',' . $page->listRows)->select();
		$member = M('member');
		foreach ($list as $key => $value) {
			unset($map);
			$map['wxid'] = $value['toUserWx'];
			$list[$key]['toUser'] = $member->where($map)->getField('wxname');
			unset($map);
			$map['wxid'] = $value['fromUserWx'];
			$from = $member->field('id,wxname')->where($map)->find();
			$list[$key]['fromUser'] = $from['wxname'];
			$list[$key]['fromUserID'] = $from['id'];

		}

		$this->assign('list', $list);
		$this->assign('page', $show);
		$this->assign('userid', $userid);
		$this->display();
	}

	public function setting(){
		$this->display();
	}
   
    #保存配置
    public function insert(){

    	$file=I('post.files');
		unset($_POST['files']);
		
		if($this->update_config($_POST,CONF_PATH.$file)){
			$state = 'SUCCESS';
          	$message = '操作成功';
		}else{
			$state = '操作失败';
		}
		echo $this->echo_json_str($state,$message,$url);
    }	
}
?>